//
//  WBHomeViewController.swift
//  weibo
//
//  Created by swift on 17/2/22.
//  Copyright © 2017年 jason. All rights reserved.
//

import UIKit
//定义全局常量
private let cellId = "cellId"

class WBHomeViewController: WBBaseViewController {
   //微博数据数组
   fileprivate lazy var listmodel = wblistviewmodel()
    //模拟延时加载数据
    
    //加载数据
    override func loaddata() {
        
        print("加载数据结束\(self.listmodel.statuslist.last?.text)")
        
        listmodel.loadstatus(pullup:self.isPullup)  { (issuccess,hasmorepullup) in
            
            //结束刷新控件
            self.refreshControl?.endRefreshing()
            //恢复上拉刷新
            self.isPullup = false
            if hasmorepullup {
                self.tableView?.reloadData()
            }
        }
    }

    @objc fileprivate func showFriends(){
        
        let vc = testViewController()
        
        navigationController?.pushViewController(vc, animated: true)
        
    }
    }
 //MARK:-表格数据源方法
extension WBHomeViewController{
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return listmodel.statuslist.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        //1取cell
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        //2设置cell
        cell.textLabel?.text = listmodel.statuslist[indexPath.row].text
        cell.detailTextLabel?.text = listmodel.statuslist[indexPath.row].text
        //3返回cell
        return cell
    }
   
    
}
//MARK:-设置界面
extension WBHomeViewController{
    //重写父类的方法
    override func setuptableview() {
        super.setuptableview()

        //设置导航的按钮
        
        navitem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(showFriends))
        
//        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(showFriends))
        //注册原型cell
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
    }
}
